package 力扣._00周赛._414周赛.问题2;

import java.util.Arrays;

public class Solution {
    public int maxPossibleScore(int[] start, int d) {
        // 排序
        // 选择的值的分布要尽可能均匀，以便最小绝对差 最大
        //
        Arrays.sort(start);
        // 第一个选 start[0], 最后一个选start[len-1]+d
        int min = Integer.MAX_VALUE;
        int l = start[0], r = start[start.length - 1] + d;
        int avg = (r - l) / (start.length - 1);
        int last = l;
        for (int i = 1; i < start.length; i++) {
            System.out.println(last);
            if (start[i] <= last + avg && last + avg <= start[i] + d) {
                min = Math.min(min, last + avg - last);
                last = last + avg;
            } else if (start[i] > last + avg) {
                min = Math.min(min, start[i] - last);
                last = start[i];
            } else {
                min = Math.min(min, start[i] + d - last);
                last = start[i] + d;
            }
        }
        return min;

    }

    public static void main(String[] args) {
        int i = new Solution().maxPossibleScore(new int[]{3,2,9,2,0},3);
        System.out.println(i);
    }
}
